
import java.util.ArrayList;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;


public class AddWorkingPeriodTest {
	
	private int size;
	private WorkSchedule schedule;
	private Utils utils;
	@Before
	public void setUp(){
		size = 8;
		schedule = new WorkSchedule(size);
		utils = new Utils();
	}
	
	@Test
	public void testAddWorkingPeriod(){
		//Trying to add when not having a set any "required number"
		//New TestCase: workingemp = requirednumber
		utils.UpdatePreviousScheduleList(schedule, size);
		Assert.assertFalse(schedule.addWorkingPeriod("oskar", 0, size-1));
		utils.isAllValueUnchanged(schedule);
		
		
		//New TestCase: endtime > size-1
		schedule.setRequiredNumber(2, 0, size-1);
		utils.UpdatePreviousScheduleList(schedule, size);
		Assert.assertFalse(schedule.addWorkingPeriod("jacob", 0, size));
		utils.isAllValueUnchanged(schedule);
		
		//New TestCase: Starttime < 0
		utils.UpdatePreviousScheduleList(schedule, size);
		Assert.assertFalse(schedule.addWorkingPeriod("erik", -3, 1));
		utils.isAllValueUnchanged(schedule);
		
		//New TestCase: endtime < starttime
		//BUG!
		utils.UpdatePreviousScheduleList(schedule, size);
		Assert.assertFalse(schedule.addWorkingPeriod("bertil", 3, 1));
		utils.isAllValueUnchanged(schedule);
		
		//Testing adding same person multiple times
		//New TestCase: WorkingEmployees contains Employee
		//New TestCase: endTime = size-1
		//New TestCase: starttime = 0
		schedule.setRequiredNumber(6, 0, size-1);
		utils.UpdatePreviousScheduleList(schedule, size);
		Assert.assertTrue(schedule.addWorkingPeriod("peter", 0, size-1));
		utils.scheduleShouldContainEmployee(schedule,"peter",0,size-1);
		
		utils.UpdatePreviousScheduleList(schedule, size);
		//since peter already is in the list nothing should happen
		Assert.assertFalse(schedule.addWorkingPeriod("peter", 1, 3));
		utils.isAllValueUnchanged(schedule);
		
		// Adding 4 employees at the same hour with max nr 3
		//adding number 1
		schedule = new WorkSchedule(size);
		schedule.setRequiredNumber(3, 0, size-1);
		utils.UpdatePreviousScheduleList(schedule, size);
		Assert.assertTrue(schedule.addWorkingPeriod("sigurt", 0, size-1));
		utils.scheduleShouldContainEmployee(schedule,"sigurt", 0, size-1);
		
		//adding number 2
		utils.UpdatePreviousScheduleList(schedule, size);
		Assert.assertTrue(schedule.addWorkingPeriod("sebbe", 0, 2));
		//check if the schedule have sigurt and sebbe in given hours
		utils.scheduleShouldContainEmployee(schedule,"sigurt", 0, size-1);
		utils.scheduleShouldContainEmployee(schedule,"sebbe", 0, 2);
		//checking the other hours is unchanged
		utils.isOtherValuesUnchanged(schedule,0, 2);
		
		//adding number 3
		//New TestCase: starttime==endtime
		utils.UpdatePreviousScheduleList(schedule, size);
		Assert.assertTrue(schedule.addWorkingPeriod("david", 2, 2));
		//check if the schedule have sigurt, sebbe and david in given hours 
		utils.scheduleShouldContainEmployee(schedule,"sigurt", 0, size-1);
		utils.scheduleShouldContainEmployee(schedule,"sebbe", 0, 2);
		utils.scheduleShouldContainEmployee(schedule,"david", 2, 2);
		utils.isOtherValuesUnchanged(schedule,0, 2);
		
		//adding number 4
		//New TestCase: workingemployees = requirednumber
		utils.UpdatePreviousScheduleList(schedule, size);
		Assert.assertFalse(schedule.addWorkingPeriod("obama", 0, 2));
		utils.scheduleShouldContainEmployee(schedule,"sigurt", 0, size-1);
		utils.scheduleShouldContainEmployee(schedule,"sebbe", 0, 2);
		utils.scheduleShouldContainEmployee(schedule,"david", 2, 2);
		// the list should be full and obama should not be added
		utils.isAllValueUnchanged(schedule);
		
	}

}
